// 请求管理
import axios from '../http/index'
import { delCookie } from '../../utils/aqi'
import router from '../../router'
import 'element-ui/lib/theme-chalk/index.css'
import { Message } from 'element-ui'

// get请求
export const get = (url) => {
  return axios.get(url).then(data => {
    return Promise.resolve(data)
  })
}

// post请求
export const post = (url, params) => {
  return axios.post(url, params).then(data => {
    if (data.data.data == 401) {
      delCookie('token')
      router.push('/Login')
      // path: '/Login'
      // path: '/web/cmsview/dial/0.2/Login'
      // query: { redirect: router.currentRoute.path }
      // })
    } else if (data.data.code == 500) {
      data.data.msg && Message.error(data.data.msg)
      if (data.data.msg == '没有权限，请联系管理员授权') {
        // if (window.location.pathname == '/web/cmsview/dial/0.2/Home') {
        //     if (window.location.pathname != '/login') {
        //         router.replace({ path: '/login', })
        //     }
        // } else {
        //     router.replace({ path: '/web/cmsview/dial/0.2/Home', })
        // }
      }
    } else {
      return Promise.resolve(data.data)
    }
  })
}

export const deletes = (url, params) => {
  return axios.delete(url, params).then(data => {
    return Promise.resolve(data)
  })
}

export const put = (url, params) => {
  return axios.put(url, params).then(data => {
    return Promise.resolve(data)
  })
}
